package ch3.taskscheduler;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class ScheduledTaskService {
    private static final SimpleDateFormat dateFormat=new SimpleDateFormat("HH:mm:ss");
    @Scheduled(fixedRate = 5000)
    public void reportCurrenTime(){
        System.out.println("每隔5秒执行一次"+dateFormat.format(new Date()));
    }
    @Scheduled(cron = "0 28 11 ? * *" )
    public  void fixTimeExection(){
        System.out.println("在指定时间执行"+dateFormat.format(new Date()));
    }
}
